﻿using Prism.Events;
using Prism.Ioc;
using Prism.Regions;
using DLL.NET70.Infrastructure.Prism;
using DLL.NET70.Infrastructure.Prism.MVVM;
using System;
using Prism.Commands;

namespace PrismModule.MultyStationRobot.ViewModels
{
    public class PUC_MS_ParamViewModel : CMVVMBase, IRegionMemberLifetime
    {
        public bool KeepAlive
        {
            get
            {
                //return false;//这个的作用是，只要离开当前切面，就注销掉当前页面
                return false;//这个的作用是，只要离开当前切面，就注销掉当前页面
            }
        }

        public override void Loaded()
        {
            //默认加载控制卡设置参数
            string navigatePath = "";
            navigatePath = "PUC_CardSelected";
            Navigate(navigatePath);
            base.Loaded();
        }

        public override void UnLoaded()
        {
            foreach (var region in RegionManager.Regions)
            {
                IRegion region1 = region;
            }
            //RegionManager.Regions.Remove("MultyStationParamRegion");
            base.UnLoaded();
        }

        private IContainerExtension _container;

        public PUC_MS_ParamViewModel(IRegionManager regionManager,
            IEventAggregator eventAggregator,
            IApplicationCommands applicationCommands,
            IContainerExtension container) :
            base(regionManager, eventAggregator, applicationCommands)
        {
            NavigateCommand = new DelegateCommand<string>(Navigate);
        }

        public DelegateCommand<string> NavigateCommand { get; private set; }

        private void Navigate(string viewName)
        {
            Navigate("MSParamRegion", viewName);
        }

        private void Navigate(string region, string navigatePath)
        {
            if (navigatePath != null)
            {
                RegionManager.RequestNavigate(region, navigatePath);
            }
        }
    }
}